//
//  LSWeatherView.m
//  KuaiYi
//
//  Created by 袁应荣 on 2016/11/13.
//  Copyright © 2016年 HeiMa. All rights reserved.
//

#import "LSWeatherView.h"
#import <UIImageView+WebCache.h>


@interface LSWeatherView ()

@property (weak, nonatomic) IBOutlet UIImageView *icon_weatherImageVIew;
@property (weak, nonatomic) IBOutlet UILabel *WeatherLabel;
@property (weak, nonatomic) IBOutlet UILabel *currentCityLabel;
@property (weak, nonatomic) IBOutlet UILabel *temperatureLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;



@end
@implementation LSWeatherView

- (void)setWeathers:(NSArray<LSWeatherModel *> *)weathers
{
    _weathers = weathers;
    LSWeatherModel *weather = weathers[0];
    NSDate *currentDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd-HH";
    NSString *strDate = [formatter stringFromDate:currentDate];
    NSString *strHour = [strDate componentsSeparatedByString:@"-"].lastObject;
    
    self.WeatherLabel.text = weather.weather;
    self.currentCityLabel.text = @"深圳";
    self.temperatureLabel.text = weather.temperature;
    self.dateLabel.text = weather.date;
    
    
    
    int hour = [strHour intValue];
    if (hour >= 6 && hour <= 18) {
        [self.icon_weatherImageVIew sd_setImageWithURL:[NSURL URLWithString:weather.dayPictureUrl] placeholderImage:[UIImage imageNamed:@"icon_weather_default"]];
    } else {
        [self.icon_weatherImageVIew sd_setImageWithURL:[NSURL URLWithString:weather.nightPictureUrl] placeholderImage:[UIImage imageNamed:@"icon_weather_default"]];
    }

}

@end
